﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZDSoft.UPMS.Model.BusinessPart;
using ZDSoft.UPMS.Core;
using ZDSoft.UPMS.Service.BusinessPart;
using NHibernate.Criterion;

namespace ZDSoft.UPMS.Web.Controllers
{
    public class SituationTypeController : Controller
    {
        /// <summary>
        /// 情况类型列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {

            return View();
        }

        /// <summary>
        /// 新建考察情况类型
        /// </summary>
        /// <returns></returns>
        public ActionResult Create()
        {
            IList<SituationType> SituationTypeList = Container.Instance.Resolve<ISituationTypeService>().FindAll();
            TempData["type"] = FindAllType(SituationTypeList);
            return View();
        }
        [HttpPost]
        public string Create(string id, string pid, string name)
        {
            id = Container.Instance.Resolve<ISituationTypeService>().Create(id, pid, name).ToString();
            return id;
        }
       
      
        public string FindAllType(IList<SituationType> modle)
        {
            string result = "";
            IList<SituationType> SituationTypeList = Container.Instance.Resolve<ISituationTypeService>().FindAll();
            foreach (SituationType one in Container.Instance.Resolve<ISituationTypeService>().FindAll())
            {
                if (one.Parent == null)
                {
                    result += "{id:" + one.ID + ",pId:" + 0 + ",name:\"" + one.Name + "\",open:true,iconOpen:\"../../Content/css/zTreeStyle/img/diy/1_open.png\",iconClose:\"../../Content/css/zTreeStyle/img/diy/1_close.png\",icon:\"../../Content/css/zTreeStyle/img/diy/3.png\"},";
                }
                else
                {
                    result += "{id:" + one.ID + ",pId:" + one.Parent.ID + ",name:\"" + one.Name + "\",icon:\"../../Content/css/zTreeStyle/img/diy/3.png\"},";
                }
            }
            return result;
        }

        public void GetSituationByID(string id)
        {
            Container.Instance.Resolve<ISituationTypeService>().Delete(int.Parse(id));
        }


    }
}


